package com.nebulas.nettyhex.server;


import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

public class TestMain {

    public static void main(String[] args) {
        double value = 37.1;
        byte[] byteArray = doubleToByteArray(value);

    }

    public static double hexStringToDouble(byte[] bytes) {
        // 将字节数组转换为long类型的位表示
        long bits = 0;
        for (int i = (bytes.length - 1); i >= 0; i--) {
            bits = (bits << 8) | (bytes[i] & 0xff);
        }

        // 将位表示转换为double类型
        return Double.longBitsToDouble(bits);
    }

    public static byte[] doubleToByteArray(double value) {
        ByteBuffer buffer = ByteBuffer.allocate(Double.BYTES); // 分配8个字节的缓冲区
        buffer.putDouble(value); // 将double值写入缓冲区
        return buffer.array(); // 返回缓冲区的字节数组
    }

}
